package com.tiancheng.trade.payment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tiancheng.trade.commom.core.enums.SettleStatusEnum;
import com.tiancheng.trade.commom.core.enums.VerificationStatusEnum;
import com.tiancheng.trade.commom.core.exception.Asserts;
import com.tiancheng.trade.payment.channel.bo.UnifiedOrderSettleBO;
import com.tiancheng.trade.payment.enums.FlowStatusEnum;
import com.tiancheng.trade.payment.mapper.PaymentBillMapper;
import com.tiancheng.trade.payment.mapper.PaymentFlowDetailMapper;
import com.tiancheng.trade.payment.mapper.PaymentOrderMapper;
import com.tiancheng.trade.payment.model.PaymentBill;
import com.tiancheng.trade.payment.model.PaymentBillDetail;
import com.tiancheng.trade.payment.model.PaymentFlowDetail;
import com.tiancheng.trade.payment.model.PaymentOrder;
import com.tiancheng.trade.payment.service.IPaymentBillService;
import com.tiancheng.trade.payment.util.helper.PaymentIdHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 支付账单 service impl
 */
@Service
public class PaymentBillServiceImpl extends ServiceImpl<PaymentBillMapper, PaymentBill> implements IPaymentBillService {

    @Resource
    private PaymentOrderMapper paymentOrderMapper;
    @Resource
    private PaymentFlowDetailMapper paymentFlowDetailMapper;

    @Override
    public boolean genBill(PaymentOrder flow, List<PaymentFlowDetail> flowDetails, List<UnifiedOrderSettleBO> subSettles) {

        /*PaymentBill paymentBill = new PaymentBill();
        paymentBill.setFlowId(flow.getFlowId());
        paymentBill.setBillNo(PaymentIdHelper.getSettleFlowId(paymentBill.getFlowId()));
        paymentBill.setTradeTime(flow.getFlowTime());
        paymentBill.setOrderAmount(flow.getOrderAmount());
        paymentBill.setPayAmount(flow.getAmount());

        List<PaymentBillDetail> paymentBillDetails = new ArrayList<>();
        for (PaymentFlowDetail flowDetail : flowDetails) {
            PaymentBillDetail paymentBillDetail = new PaymentBillDetail();
            paymentBillDetail.setFlowId(flowDetail.getFlowId());
            paymentBillDetail.setSubFlowId(flowDetail.getSubFlowId());
            paymentBillDetail.setBillNo(paymentBill.getBillNo());
            paymentBillDetail.setTradeTime(paymentBill.getTradeTime());
            paymentBillDetail.setSettleRuleCode(flowDetail.getSettleRuleCode());
            // 平台佣金
            paymentBillDetail.setPlatformAmount();
            // 平台商户
            paymentBillDetail.setSettleMerchantAmount();
            // 商户金额
            paymentBillDetail.setMerchantAmount();
            // 最终-平台佣金
            paymentBillDetail.setSettlePlatformAmount();
            // 最终-商户所得
            paymentBillDetail.setSettleMerchantAmount();
            // 退款金额
            paymentBillDetail.setRefundAmount();
            paymentBillDetail.setVerificationStatus(VerificationStatusEnum.WAIT.getCode());
            paymentBillDetail.setSettleStatus(SettleStatusEnum.WAIT.getCode());
            paymentBillDetail.setCreateTime(LocalDateTime.now());
            paymentBillDetails.add(paymentBillDetail);
        }
        // 平台佣金
        paymentBill.setPlatformMerchant();
        // 平台商户
        paymentBill.setSettleMerchantAmount();
        paymentBill.setCreateTime(LocalDateTime.now());*/
        return true;
    }

}
